package com.bytedance.dao;


import com.bytedance.dataobject.A;
import com.bytedance.dataobject.B;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

public class BProvider {

    public String insertSQL() {
        String sql = new SQL()
                .INSERT_INTO("B")
                .VALUES("A", "#{A}")
                .VALUES("B", "#{B}")
                .VALUES("C", "#{C}")
                .VALUES("D", "#{D}")
                .VALUES("E", "#{E}")
                .VALUES("F", "#{F}")
                .VALUES("aa", "#{aa}")
                .VALUES("bb", "#{bb}")
                .VALUES("cc", "#{cc}")
                .VALUES("dd", "#{dd}")
                .VALUES("ee", "#{ee}")
                .toString();
        return sql;
    }

    public String updateSQL() {
        String sql = new SQL()
                .UPDATE("B")
                .SET("B=#{B}")
                .SET("C=#{C}")
                .SET("D=#{D}")
                .SET("E=#{E}")
                .SET("F=#{F}")
                .SET("aa=#{aa}")
                .SET("bb=#{bb}")
                .SET("cc=#{cc}")
                .SET("dd=#{dd}")
                .SET("ee=#{ee}")
                .WHERE("A=#{A}")
                .AND()
                .WHERE("C=#{C}")
                .toString();
        return sql;
    }

    public String selectByIdSQL() {
        String sql = new SQL()
                .SELECT("*")
                .FROM("B")
                .WHERE("A=#{A}")
                .AND()
                .WHERE("C=#{C}")
                .toString();
        return sql;
    }

    public String deleteByIdSQL() {
        String sql = new SQL()
                .DELETE_FROM("B")
                .WHERE("A=#{a}")
                .AND()
                .WHERE("C=#{c}")
                .toString();
        return sql;
    }

    public String deleteByCSQL() {
        String sql = new SQL()
                .DELETE_FROM("B")
                .WHERE("C=#{C}")
                .toString();
        return sql;
    }

    public String insertListSQL(@Param("bList") List<B> bList) {
        return new SQL() {{
            INSERT_INTO("B").
                    INTO_COLUMNS("A", "B", "C", "D", "E", "aa", "bb", "cc", "dd", "ee",
                            "aa_correct", "bb_correct", "cc_correct", "dd_correct", "ee_correct");
            for (B b : bList) {
                INTO_VALUES(b.getA(), b.getB(), b.getC(), b.getD(), b.getE(),
                        b.getAa().toString(), b.getBb().toString(), b.getCc().toString(),
                        b.getDd().toString(), b.getEe().toString(), b.getAaCorrect().toString(), b.getBbCorrect().toString(),
                        b.getCcCorrect().toString(), b.getDdCorrect().toString(), b.getEeCorrect().toString())
                        .ADD_ROW();
            }
        }}.toString();
    }

    public String selectAllSQL() {
        String sql = new SQL()
                .SELECT("*")
                .FROM("B")
                .toString();
        return sql;
    }

    public String selectCountSQL() {
        String sql = new SQL()
                .SELECT("count(*)")
                .FROM("B")
                .WHERE("${column} = 1")
                .toString();
        return sql;
    }
}
